home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: ODBC SQL problems
- Date: 23 Mar 1996 21:25:16 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4j1q7s$q4r@arl-news-svc-3.compuserve.com>
- NNTP-Posting-Host: dd50-130.compuserve.com
-
- matthew@iapps.com (Matthew Baird) s'Θcrit :
- > I've written an application that allows the user to pass SQL queries to an
- > ODBC datasource, then dynamically binds the columns and displays the results
- > in a template. I have two problems currently:
- >
- > How do I truncate the data in a SQL_TIMESTAMP field so that when I
- > display it, the field shows only the date portion? Here is a snippet of code:
- >
- > case SQL_TIMESTAMP:
- > data[i] = new UCHAR[24];
- > rc = SQLBindCol(hstmt, i+1, SQL_C_CHAR, data[i], 24, &outlen[i]);
- > break;
- >
- > Interestingly it doesn't matter how much space I allocate in my new UCHAR
- > line, but if I change the 24 in the SQLBindCol, I get strange errors.
- >
-
- Don't bind SQL_C_CHAR variables, but bind a more appropriate
- type which allows date/time manipulation. Depending on your
- development system, you should find a type like the DBDATETIME
- structure on which operations are possible like extracting the
- date and time numeric values. Binding strings is not portable
- because it is RDBMS dependant. Another solution is to select
- a SQL-provided conversion to a string.
-
- >
- > My second question is if a user enters a query that is made of two
- > distinct queries ie.
- >
- > Delete from table where user='smith' Select * from table
- >
- > how do I fetch only the results from the valid SELECT statement?
- >
-
- Use a loop which reads each result set separately. This is not
- portable to some RDBMS (Oracle supports only one result set,
- Sybase and Microsoft SQL-Server do however).
- Second solution: don't use ODBC, but use more performant API's
- like the DB-Library for Sybase or Microsoft SQL-Server.
-
- > Thanks,
- >
- > Matthew@iapps.com
- >
-
-